package com.yonyou.pmclouds.billview.rmiimpl.buzi;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.PageObject;
import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import com.yonyou.pmclouds.billview.entity.BillViewQueryVO;
import com.yonyou.pmclouds.billview.rmitf.IBillViewBuziService;
import com.yonyou.pmclouds.billview.util.BillViewUtil;
import com.yonyou.pmclouds.safetyrectification.entity.SafetyRectificationVO;
import com.yonyou.pmclouds.safetyrectification.service.ISafetyRectificationQuery;
import com.yonyou.pmclouds.safetyrectification.util.SafetyRectifyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 安全整改适配单据查看后台查询实现类
 *
 * @author th
 * @date 2019/11/4 17:20
 */
@Component
public class SafetyRectifyBuziServiceImpl implements IBillViewBuziService {
    @Autowired
    private ISafetyRectificationQuery query;

    @Override
    public String getBillType() {
        return BillTypeConst.SAFETY_RECTIFICATION_BILLTYPE;
    }

    @Override
    public PageObject<Object> queryBillList(BillViewQueryVO billViewQueryVO) throws BusinessException {
        PageObject<Object> safetyPage = query.queryByCondition(billViewQueryVO.getPkProject(), billViewQueryVO.getCreators(),
                billViewQueryVO.getStartTime(), billViewQueryVO.getEndTime(), billViewQueryVO.getBillStatus(),
                billViewQueryVO.getPageStart(), billViewQueryVO.getPageSize());

        return safetyPage;
    }

    @Override
    public SuperVO queryBillDetail(String pkBill) throws BusinessException {
        SafetyRectificationVO vo = query.getById(pkBill);
        // 将整改期限、创建时间、单据状态、严重程度翻译成具有业务含义的文字
        BillViewUtil.setFormatDate(new SafetyRectificationVO[]{vo}, new String[]{SafetyRectificationVO.DEADLINE},
                new String[]{SafetyRectificationVO.STR_DEADLINE});
        BillViewUtil.setFormatDate(new SafetyRectificationVO[]{vo}, new String[]{CommonFieldConst.CREATIONTIME},
                new String[]{SafetyRectificationVO.STR_CREATIONTIME});
        vo.setStrBillStatus(SafetyRectifyUtil.transBillStatus(vo));
        vo.setStrSeverityLevel(SafetyRectifyUtil.transSeverityLevel(vo));
        // 是否超期
        vo.setOverTime(SafetyRectifyUtil.checkOverTime(vo));

        return vo;
    }
}
